package com.opensistemas.spm.model;

import org.appfuse.model.BaseObject;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import java.io.Serializable;

@Entity
@Table(name="project_date")
@Inheritance(strategy= InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="project_date_type",  discriminatorType = DiscriminatorType.STRING)
abstract public class ProjectDate extends BaseObject implements Serializable {
    private Long id;
    private Project project;
    private Date date;
    private String log;
    private String projectDateType;

    @Id  @GeneratedValue(strategy = GenerationType.AUTO)    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="project_id", nullable=false)
    public Project getProject() {
        return this.project;
    }
    
    public void setProject(Project project) {
        this.project = project;
    }
    
    @Column(name="date", nullable=false, length=0)
    public Date getDate() {
        return this.date;
    }
    
    public void setDate(Date date) {
        this.date = date;
    }
    
    @Column(name="log_comment", nullable=false)
    public String getLog() {
        return this.log;
    }
    
    public void setLog(String logComment) {
        this.log = logComment;
    }
    
    @Column(name="project_date_type", nullable=false, length=50, insertable=false, updatable = false)
    public String getProjectDateType() {
        return this.projectDateType;
    }
    
    public void setProjectDateType(String projectDateType) {
        this.projectDateType = projectDateType;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ProjectDate pojo = (ProjectDate) o;

        if (project != null ? !project.equals(pojo.project) : pojo.project != null) return false;
        if (date != null ? !date.equals(pojo.date) : pojo.date != null) return false;
        if (log != null ? !log.equals(pojo.log) : pojo.log != null) return false;
        if (projectDateType != null ? !projectDateType.equals(pojo.projectDateType) : pojo.projectDateType != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (project != null ? project.hashCode() : 0);
        result = 31 * result + (date != null ? date.hashCode() : 0);
        result = 31 * result + (log != null ? log.hashCode() : 0);
        result = 31 * result + (projectDateType != null ? projectDateType.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("project").append("='").append(getProject()).append("', ");
        sb.append("date").append("='").append(getDate()).append("', ");
        sb.append("log").append("='").append(getLog()).append("', ");
        sb.append("projectDateType").append("='").append(getProjectDateType()).append("'");
        sb.append("]");
      
        return sb.toString();
    }

}
